<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="save()" type="primary">备份</a-button>
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('评论')">导出</a-button>-->
    </div>

    <!-- table区域-begin -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="img" slot-scope="text, record">
          <img :src="text" alt="" width="100px" height="100px">
        </span>
        <span slot="action" slot-scope="text, record">
<!--      <a @click="handleDetail(record)">查看详情</a>-->
          <a @click="reload(record)">还原</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => delSQL(record)">
            <a>删除</a>
          </a-popconfirm>

        </span>

      </a-table>

  </a-card>
</template>

<script>

  import '@assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction, postAction, putAction } from '@api/manage'
  export default {
    name: 'SqlList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
    },
    data () {
      return {
        description: '评论管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'文件名称',
            align:"center",
            dataIndex: 'fileName'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/phil/common/readName",
          delete: "/phil/common/delete",
          save: "/phil/common/save",
          load: "/phil/common/load",
          listDelFlag:'/phil/common/listDelFlag',
        },
        dictOptions:{},
        status:0,
      }
    },
    created() {
    },
    computed: {
    },
    methods: {
      reload(record){
        let params = {
          fileName: record.fileName
        }
        getAction(this.url.load,params).then(res=>{
          if (res.success){
            this.$message.success(res.result)
          }else {
            this.$message.error(res.result)
          }
        })
      },
      save(){
        getAction(this.url.save).then(res=>{
          if (res.success){
            this.$message.success(res.result)
          }else {
            this.$message.error(res.result)
          }
          this.loadData()
        })
      },
      delSQL(record){
        let params = {
          fileName : record.fileName
        }

        getAction(this.url.delete,params).then(res=>{
          if (res.success){
            this.$message.success(res.result)
          }else {
            this.$message.error(res.result)
          }
          this.loadData()
        })
      },
      initDictConfig(){
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>